package com.xique.park.controller.web;

import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.request.web.chargeRule.*;
import com.xique.park.service.biz.service.IParkChargeRuleBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 收费规则
 *
 * @author xique
 */
@RestController
@RequestMapping("/web/chargeRule")
public class WebParkChargeRuleController {

    @Autowired
    private IParkChargeRuleBizService parkChargeRuleBizService;

    /**
     * 查询计费规则列表
     */
    @GetMapping("/list")
    @PreAuthorize(hasPermi = "park:chargeRule:list")
    public AjaxResult getParkChargeRuleList() {
        return parkChargeRuleBizService.getParkChargeRuleList();
    }

    /**
     * 选中计费规则信息回显
     */
    @GetMapping("/info")
    @PreAuthorize(hasPermi = "park:chargeRule:query")
    public AjaxResult getParkChargeRuleInfo(Long ruleId) {
        return parkChargeRuleBizService.getParkChargeRuleInfo(ruleId);
    }

    /**
     * 管理类型和车库组合
     */
    @GetMapping("/getMngTypeGarage")
    @PreAuthorize(hasPermi = "park:chargeRule:query")
    public AjaxResult getMngTypeGarage() {
        return parkChargeRuleBizService.getMngTypeGarage();
    }

    /**
     * 查询某种管理类型和出库是否有设置过计费规则
     */
    @PostMapping("/getMngTypeGarageRule")
    @PreAuthorize(hasPermi = "park:chargeRule:query")
    public AjaxResult getMngTypeGarageRule(@Validated @RequestBody MngTypeGarageRuleRequest request) {
        return parkChargeRuleBizService.getMngTypeGarageRule(request);
    }

    /**
     * 添加计费规则
     */
    @PreAuthorize(hasPermi = "park:chargeRule:add")
    @Log(title = "收费规则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addChargeRule(@Validated @RequestBody AddChargeRuleRequest request) {
        return parkChargeRuleBizService.addChargeRule(request);
    }

    /**
     * 编辑计费规则
     */
    @PreAuthorize(hasPermi = "park:chargeRule:edit")
    @Log(title = "收费规则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult editChargeRule(@Validated @RequestBody EditChargeRuleRequest request) {
        return parkChargeRuleBizService.editChargeRule(request);
    }

    /**
     * 删除计费规则
     */
    @PreAuthorize(hasPermi = "park:chargeRule:remove")
    @Log(title = "收费规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult remove(@Validated @RequestBody DeleteChargeRuleRequest request) {
        return parkChargeRuleBizService.delChargeRule(request);
    }

    /**
     * 收费规则
     */
    @PreAuthorize(hasPermi = "park:chargeRule:edit")
    @Log(title = "收费规则", businessType = BusinessType.COMMAND)
    @GetMapping("/downAll")
    public AjaxResult downAll() {
        return parkChargeRuleBizService.downAll();
    }

    /**
     * 计费测试-调用支付服务测试接口
     */
    @Log(title = "收费规则-收费测试", businessType = BusinessType.COMMAND)
    @PreAuthorize(hasPermi = "park:chargeRule:edit")
    @PostMapping("/feeTest")
    public AjaxResult feeTest(@Validated @RequestBody FeeTestRequest request) {
        return parkChargeRuleBizService.feeTest(request);
    }

}
